// Compute square
object SquareRoot {
    def main() : Unit = {
        println(new SR().computeSR(144));
    }
}

class SR {
    /* This function is not recursive
    ** This function is not very efficient because we can't use float but only int 
    */ def computeSR(num:Int) : Int = {
        //Allow to test an identifier which contains "if" statement
        var ifvariable : Int;
        //Temporary variable
        var b : Int;
        var m : Int;
        var precision :Int;
        precision = 0;
        b = num;
        ifvariable = 0;
        m=0;
        if(num<0) { 
            m = 0;
        } else {
            /* 
            ** Do a loop until we reach the precision difference
            */
          while(precision<(b-ifvariable) && !(m==(b+ifvariable)/2)) {
            m=(b+ifvariable)/2;
            if(num<(m*m)) { 
                b=m; 
            }
            else { 
                ifvariable=m; 
            }
          }
        }
        return m;
    }
}
/** End of the program **/
